/*
 * Copyright 2008 Neil Bacon
 * Distributed under the terms of the Mozilla Public License version 1.1
 * or the GNU General Public License version 3.
 */

package nb.xadd.node.impl;

import nb.util.Utils;

/** Terminal value node in EADD tree */
public abstract class AbstractValueNode extends AbstractNode {

    private final double constValue;

    protected AbstractValueNode(double constValue) {
        super();
        this.constValue = constValue;
    }

    public double getConstValue() {
        return constValue;
    }

    public abstract int getPolynomialOrder();

    protected int calcHashCode() {
        return Utils.hashCode(constValue);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null || getClass() != obj.getClass())
            return false;
        AbstractValueNode other = (AbstractValueNode) obj;
        return constValue == other.constValue;
    }

    public void appendTo(int depth, StringBuilder buf) {
        Utils.appendIndent(depth, buf);
        buf.append("id = ").append(getId()).append(", constValue = ").append(getConstValue());
    }

    @Override
    public String description() {
        String s = toString();
        return s.substring(0, s.length() - 1); // remove trailing \n
    };
}
